<template>
  <el-dialog
    :close-on-click-modal="false"
    :visible="visible"
    lock-scroll
    title="详情"
    @close="visible = false"
  >
    <section class="grid grid-cols-4 items-center mb-4">
      <p><strong class="mr-2">发布人昵称</strong>{{ entity.nickname }}</p>
      <p><strong class="mr-2">发布人ID</strong>{{ entity.user_code }}</p>
      <p><strong class="mr-2">发布时间</strong>{{ entity.created_at }}</p>
    </section>

    <section class="flex items-center mb-4">
      <p class="mr-4"><strong>发布内容</strong></p>
      <audio :src="entity.url" controls/>
    </section>

    <hr>

    <el-table :data="tableData" border class="my-4" stripe width="100%">
      <el-table-column label="回复人昵称" prop="nickname"/>
      <el-table-column label="回复人ID" prop="user_code"/>
      <el-table-column label="回复时间" prop="created_at"/>
      <el-table-column label="回复内容" prop="url">
        <template slot-scope="{row}">
          <audio :src="row.url" controls/>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      :page-size="10"
      :total="meta.total"
      background
      class="text-right mt-4"
      layout="prev, pager, next"
      @current-change="initData"
    />
  </el-dialog>
</template>

<script>
import request from '@/utils/request'

export default {
  name: 'EVDetail',
  data() {
    return {
      entity: {},
      visible: false,
      tableData: [],
      meta: {
        page: 1,
        total: 0
      }
    }
  },
  methods: {
    async show(entity) {
      this.visible = true
      this.entity = entity
      await this.initData()
    },
    async initData(page = 1) {
      const id = this.entity.id
      try {
        const { data: { list, meta } } = await request(`/dandelion/${id}/reply`, { params: { page, per_page: 10 } })
        console.log(list)
        this.tableData = list
        this.meta.page = meta.page
        this.meta.total = meta.total
      } catch (e) {
        console.error(e)
      }
    }
  }
}
</script>

<style scoped>

</style>
